﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Demo
{
    public partial class SearchStoreDemo : Form
    {
        public SearchStoreDemo()
        {
            InitializeComponent();
            store.IsAsc = true;//设为升序，便于查看
            store.OnDataChanged += (a, b, c, d, e, f) =>
            {
                dataGridView1.DataSource = store.Data;
                lbInfo.Text = String.Format("当前页：{0}|每页{1}|预读取数：{2}|当前预读页：{3}|总记录数：{4}", store.PageNumber, store.PageSize, store.StaticData.Count, store.StaticPageNumber,store.GetAllRowCount());
            };
            foreach (var prop in typeof(Model.Address).GetProperties())
            {
                cbSearch.Items.Add(prop.Name);
                cbFilter.Items.Add(prop.Name);
            }
        }
        Cocon90.Lib.Dal.Store.SearchStore<Model.Address> store = new Cocon90.Lib.Dal.Store.SearchStore<Model.Address>();
        private void 加载ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            store.Load();
        }

        private void 上一页ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            store.PageNumber--;
            store.Load();
        }

        private void 下一页ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            store.PageNumber++;
            store.Load();
        }

        private void filterIndex_Click(object sender, EventArgs e)
        {
            store.Filter(5, 15);
        }

        private void filterBtn_Click(object sender, EventArgs e)
        {
            store.Filter(cbFilter.Text, txtFilt.Text, true);
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            Dictionary<string, object> dic = new Dictionary<string, object>();
            dic.Add(cbSearch.Text, txtSear.Text);
            store.Search(dic);
        }

        private void 保存更改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var ret = store.ApplyChange();
            MessageBox.Show("执行更新数：" + ret.AllCount + "\r\n成功数：" + ret.SuccessCount + "\r\n失败数：" + ret.FailCount);
        }


    }
}
